

import pandas as pd
import jieba.posseg as pseg

def get_key(mapping, value):
    for k, v in mapping.items():
        for i in v:
            if i == value:
                return k



def columns_fill(df: pd.DataFrame, columns: list, mode='exact'):
    if mode == 'exact':
        for col in columns:
            df[col] = df[col].fillna(col)
    elif mode == 'prefix':
        for col in columns:
            for col_orig in df.columns:
                if col_orig[:len(col)] == col:
                    df[col_orig] = df[col_orig].fillna(col_orig)
    elif mode == 'suffix':
        for col in columns:
            for col_orig in df.columns:
                if col_orig[len(col):] == col:
                    df[col_orig] = df[col_orig].fillna(col_orig)

    return df


def columns_check(checks, columns):
    return set(checks) & set(columns)



def get_all_name(msg_content):
    words = pseg.cut(msg_content)
    names = []
    for word, flag in words:
        names.append(flag)
    return names



